package net.mysoft.budgetsoft.system.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.mysoft.framework.base.BaseAction;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@SuppressWarnings({"rawtypes", "unchecked"})
@Namespace("/enum")
@Scope("prototype")
@Controller
public class EnumAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8828457340521766396L;
	
	public static final String prefix = "net.mysoft.budgetsoft.system.enumtype.";
	
	@Action("/get")
	public String getEnum() {
		try {
			Class clazz = Class.forName(prefix+super.getPara("name"));
			Object[] objs = (Object[])clazz.getMethod("values").invoke(null);
			List list = new ArrayList();
			for(Object obj:objs) {
				Map map = new HashMap();
				map.put("code", obj.getClass().getMethod("getCode").invoke(obj));
				map.put("desc", obj.getClass().getMethod("getDesc").invoke(obj));
				list.add(map);
			}
			super.writeJson(list);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
